<template>
    <!-- 添加分组 -->
    <el-dialog
    title="分组编辑"
    :visible.sync="dialogVisible"
    width="40%"
    :close-on-click-modal="false"
    :before-close="handleClose"  >
        <el-form label-width="80px" v-model="form" label-position="left">
            <el-form-item label='分组名称:'>
                <el-input size="small" type='text' v-model="form.groupName" clearable placeholder="请填写分组名称" ></el-input>
            </el-form-item>
            <el-form-item label='分组编码:'>
                <el-input size="small" type='text' v-model="form.groupCode" clearable placeholder="请填写分组编码" ></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="handleClose">取 消</el-button>
            <el-button size="small" type="primary" @click="handleSubmit">提交保存</el-button>
        </span>
    </el-dialog>
</template>
<script>
    export default {
        props: ['isShow', 'id'],
        computed: {
            dialogVisible: {
                get() {
                    return this.isShow;
                },
                set() {}
            }
        },
        data() {
            return {
                form: {
                    groupCode: '',
                    groupName: ''
                }
            }
        },
        methods: {
            handleClose() {
                this.$confirm('确定关闭?').then(_ => {
                    this.$emit('cancelShow', false)
                }).catch()
            },
            handleSubmit() {
                try {
                    let {groupCode, groupName}= this.form
                    if(groupName == '') {
                        this.$message.warning('请填写分组名称')
                    }else if(groupCode == '') {
                        this.$message.warning('请填写分组编码')
                    }else{
                        let params= {
                            groupCode: groupCode,
                            groupName: groupName,
                            parentId: this.id
                        }
                        this.$server.systemControlApi.addSystemGroup(params).then(res => {
                            this.$emit('cancelShow', false)
                            this.$emit('getGroupsList')
                        })
                    }
                }catch(err) {this.$paramsError(err)}
            }
        }

    }
</script>